import numpy as np
import matplotlib.pyplot as plt
from sympy import symbols, limit, sin, exp, log

# 除法法则示例 - 特殊情况处理
def demonstrate_division_rule():
    x = symbols('x')
    
    # 情况1：正常除法（分母极限不为0）
    f1 = x**2 - 1  # lim(x->2) f1(x) = 3
    g1 = x - 1     # lim(x->2) g1(x) = 1
    lim_quotient1 = limit(f1/g1, x, 2)
    print(f"正常除法: lim(x->2)[({f1})/({g1})] = {lim_quotient1}")
    
    # 情况2：0/0型未定式
    f2 = x**2 - 4  # lim(x->2) f2(x) = 0
    g2 = x - 2     # lim(x->2) g2(x) = 0
    try:
        lim_quotient2 = limit(f2/g2, x, 2)
        print(f"0/0未定式: lim(x->2)[({f2})/({g2})] = {lim_quotient2}")
    except:
        print("0/0未定式需要特殊处理（如因式分解、洛必达法则等）")
    
    # 展示0/0未定式的处理
    simplified_f2g2 = (x**2 - 4)/(x - 2)
    lim_simplified = limit(simplified_f2g2, x, 2)
    print(f"化简后: lim(x->2)[(x^2-4)/(x-2)] = lim(x->2)(x+2) = {lim_simplified}")

demonstrate_division_rule()